package com.lc.luzhengtang.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.lc.luzhengtang.R;
import com.lc.luzhengtang.base.BaseActivity;
import com.lc.luzhengtang.bean.CommenBean_Forget;
import com.lc.luzhengtang.conn.ConnForget;
import com.lc.luzhengtang.util.LovelyToast;
import com.lc.luzhengtang.util.Validator;
import com.lc.luzhengtang.view.ClearEditText;
import com.zcx.helper.http.AsyCallBack;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/5/5.
 */
public class Forget2NextActivity extends BaseActivity {

    @BindView(R.id.img_news)
    ImageView imgNews;
    @BindView(R.id.text_title)
    TextView textTitle;
    @BindView(R.id.img_pwd)
    ImageView imgPwd;
    @BindView(R.id.edit_newpwd)
    ClearEditText editNewpwd;
    @BindView(R.id.img_submit)
    ImageView imgSubmit;
    @BindView(R.id.edit_repwd)
    ClearEditText editRepwd;
    @BindView(R.id.btn_settings)
    Button btnSettings;
    String string;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forget_next);
        ButterKnife.bind(this);
        textTitle.setText("忘记密码");
        string = getIntent().getStringExtra("mobil");
        Log.e("dr", string);

    }

    @OnClick({R.id.img_news, R.id.text_title, R.id.img_pwd, R.id.edit_newpwd, R.id.img_submit, R.id.edit_repwd, R.id.btn_settings})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_news:
                finish();
                break;
            case R.id.text_title:
                break;
            case R.id.img_pwd:
                break;
            case R.id.edit_newpwd:
                break;
            case R.id.img_submit:
                break;
            case R.id.edit_repwd:
                break;
            case R.id.btn_settings:
                if (TextUtils.isEmpty(editNewpwd.getText().toString())) {
                    LovelyToast.makeText(Forget2NextActivity.this, "密码不能为空", 0, LovelyToast
                            .SUCCESS, LovelyToast.SCALE);
                } else if (!Validator.isPassword(editNewpwd.getText().toString())) {
                    LovelyToast.makeText(Forget2NextActivity.this, "请输入6~12位数字或英文密码", 0, LovelyToast
                            .SUCCESS, LovelyToast.SCALE);
                } else if (TextUtils.isEmpty(editRepwd.getText().toString())) {
                    LovelyToast.makeText(Forget2NextActivity.this, "再次输入的密码不能为空", 0, LovelyToast
                            .SUCCESS, LovelyToast.SCALE);
                } else if (!Validator.isPassword(editRepwd.getText().toString())) {
                    LovelyToast.makeText(Forget2NextActivity.this, "请输入6~12位数字或英文密码", 0, LovelyToast
                            .SUCCESS, LovelyToast.SCALE);
                } else if (!editNewpwd.getText().toString().equals(editRepwd.getText().toString())) {
                    LovelyToast.makeText(Forget2NextActivity.this, "两次输入的密码不一致", 0, LovelyToast
                            .SUCCESS, LovelyToast.SCALE);
                } else {
                    settingspayPwd();
                }

                break;
        }
    }


    // edit_phone edit_pwd_pay
    public void settingspayPwd() {
        new ConnForget(string, editNewpwd.getText().toString(), new AsyCallBack<CommenBean_Forget>() {
            @Override
            public void onStart(int type) throws Exception {
                super.onStart(type);
            }

            @Override
            public void onSuccess(String toast, int type, Object o, CommenBean_Forget commenBean) throws Exception {
                super.onSuccess(toast, type, o, commenBean);
                if (commenBean.getCode() == 200) {
                    LovelyToast.makeText(Forget2NextActivity.this, "设置密码成功", 0, LovelyToast
                            .SUCCESS, LovelyToast.SCALE);
                    startActivity(new Intent(Forget2NextActivity.this, LoginActivity.class));
                    finish();
                } else {
                    LovelyToast.makeText(Forget2NextActivity.this, commenBean.getMessage(), 0, LovelyToast
                            .SUCCESS, LovelyToast.SCALE);
                }
            }

            @Override
            public void onFail(String toast, int type) throws Exception {
                super.onFail(toast, type);
            }

            @Override
            public void onEnd(String toast, int type) throws Exception {
                super.onEnd(toast, type);
            }
        }


        ).execute(Forget2NextActivity.this, false);
    }


}
